package com.metagurukul.informer.service;

import java.sql.SQLException;

import com.metagurukul.informer.dao.AnswersDAO;
import com.metagurukul.informer.valueObjects.Answers;

/**
 * Class AnswerService to handle functions related to the answers
 * @author 
 *
 */
public class AnswerService {
	private int answerId;
	public AnswerService(){}
	public AnswerService(int answerId) {
		this.answerId = answerId;
	}
	
	/**
	 * ...Method for calling approveAnswer method of DAO class
	 * @param context
	 * @return true if approval successful
	 */
	public boolean approveAnswer() throws SQLException {
		AnswersDAO answerdao = new AnswersDAO();
		return answerdao.approveAnswer(answerId);
	}
	
	/**
	 * ...Method for calling insertAnswer method of DAO class providing values for insertion
	 * @param question_id
	 * @param answer
	 * @param context
	 * @param user
	 */
	public void insertAnswer(int question_id, String answer, String user) throws SQLException {
		new AnswersDAO().insertAnswer(new Answers(0, answer, false, user, question_id, null));
	}
	
	/**
	 * ...Method for calling deleteAnswer of DAO proving the answer_id for deletion
	 * @param context
	 * @return true if deletion successful
	 */
	public boolean deleteAnswer() throws SQLException {
		AnswersDAO answersdao = new AnswersDAO ();
		return answersdao.DeleteById(answerId);		
	}
	
}
